package 学生成绩查询管理系统.界面;

import 学生成绩查询管理系统.功能.AccountManager;
import 学生成绩查询管理系统.功能.ClassroomManager;
import 学生成绩查询管理系统.功能.CourseManager;
import 学生成绩查询管理系统.功能.ScoreManager;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class StudentSystem extends JFrame implements WindowListener,ActionListener {
    private JMenuItem reLogin;
    private JMenuItem menu;
    private JMenuItem exit;
    private JMenuItem aboutMe;
    private JPanel root;
    JButton score;
    JButton classroom ;
    JButton course;
    JButton account;
    private MyTray myTray; // 将MyTray对象设置为类成员变量
    private JLabel label1;
    String path="C:\\Users\\23513\\Desktop\\学生成绩管理系统\\";
    private DefaultTableModel tableModel;

    public StudentSystem() {
        initJframe();
        initMenu();
    setVisible(true);

}
private void initJframe(){


   this.setTitle("学生成绩查询管理系统");
   this.setSize(600,450);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Font centerFont=new Font("正楷",Font.PLAIN,15);
    Font FFont=new Font("华文行楷",Font.PLAIN,35);
    //添加标语
    label1= new JLabel("欢迎来到学生成绩查询管理系统", JLabel.CENTER);
    getContentPane().add(label1);
    label1.setBounds(40,100,500,200);

    label1.setFont(FFont);
    //添加按钮
    score = new JButton("成绩管理");
    classroom = new JButton("班级管理");
    course = new JButton("课程管理");
     account = new JButton("账号管理");

    score.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            SwingUtilities.invokeLater(() -> {
                ScoreManager scoreManager = new ScoreManager();
                scoreManager.setVisible(true);
            });
            dispose();
        }
    });

    classroom.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
            SwingUtilities.invokeLater(() -> {
                ClassroomManager classroomManager = new ClassroomManager();
                classroomManager.setVisible(true);
            });
        }
    });

    course.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
            SwingUtilities.invokeLater(() -> {
                CourseManager courseManager = new CourseManager();
                courseManager.setVisible(true);
            });
        }
    });

    account.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
            SwingUtilities.invokeLater(() -> {
                AccountManager classroomManager = new AccountManager();
                classroomManager.setVisible(true);
            });
        }
    });


    score.setBackground(Color.CYAN);
    classroom.setBackground(Color.CYAN);
    course.setBackground(Color.CYAN);
    account.setBackground(Color.CYAN);

    score.setBounds(20,5,100,30);
    classroom.setBounds(20+150,5,100,30);
    course.setBounds(20+300,5,100,30);
    account.setBounds(20+450,5,100,30);
    Font centerFont1=new Font("宋体",Font.PLAIN,15);

    score.setOpaque(false);
    classroom.setOpaque(false);
    course.setOpaque(false);
    account.setOpaque(false);

    score.setFont(centerFont1);
    classroom.setFont(centerFont1);
    course.setFont(centerFont1);
    account.setFont(centerFont1);
    this.getContentPane().add(score);
    this.getContentPane(). add(classroom);
    this.getContentPane().add(course);
    this.getContentPane(). add(account);



    // 修改图标
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image img = tk.getImage("imge\\成绩录入2.png");
    setIconImage(img);

    // 设置背景图片
    ImageIcon imageIcon = new ImageIcon("imge\\主界面2.png");
    JLabel label = new JLabel(imageIcon);
    getContentPane().add(label, BorderLayout.CENTER);
   setLocationRelativeTo(null);//居中显示
}
private void initMenu() {
        JMenuBar jMenuBar = new JMenuBar();
        JMenu about = new JMenu("关于我");
        JMenu function = new JMenu("功能");
        aboutMe = new JMenuItem("QQ二维码");
        reLogin = new JMenuItem("重新登录");
        menu = new JMenuItem("主页");
        exit = new JMenuItem("退出");

        about.add(aboutMe);
        function.add(reLogin);
        function.add(menu);
        function.add(exit);

        aboutMe.addActionListener(this);
        reLogin.addActionListener(this);
        menu.addActionListener(this);
        exit.addActionListener(this);

        jMenuBar.add(about);
        jMenuBar.add(function);
        this.setJMenuBar(jMenuBar);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 获取当前被点击的条目对象
        Object obj = e.getSource();
        if (obj == reLogin) {
            dispose();
            new Login();
        } else if (obj == menu) {
            dispose();
            new StudentSystem();
        } else if (obj == exit) {
            System.exit(0);
        } else if (obj == aboutMe) {
            // 创建一个弹框对象
            JDialog jDialog = new JDialog();
            Toolkit tk = Toolkit.getDefaultToolkit();
            Image img = tk.getImage("imge\\成绩录入2.png");
            jDialog.setIconImage(img);
            // 创建一个管理图片的容器对象JLabel
            JLabel jLabel = new JLabel(new ImageIcon("imge\\about.png"));
            // 设置位置和宽高
            jLabel.setBounds(0, 0, 300, 380);
            // 把图片添加到弹框当中
            jDialog.getContentPane().add(jLabel);
            // 给弹框设置大小
            jDialog.setSize(400, 400);
            // 让弹框置顶
            jDialog.setAlwaysOnTop(true);
            // 让弹框居中
            jDialog.setLocationRelativeTo(null);
            // 弹框不关闭则无法操作下面的界面
            jDialog.setModal(true);
            // 让弹框显示出来
            jDialog.setVisible(true);
        }

    }


private  void initcombox(){

       //定义标签组件
        JLabel score = new JLabel("成绩管理：");
        JLabel classroom = new JLabel("班级管理：");
        JLabel course = new JLabel("课程管理：");
        JLabel account = new JLabel("账号管理：");


        //定义字符串数组对象
        String[] score1 = {
               "成绩管理", "添加成绩", "删除成绩","查询成绩 ","修改成绩"
        };
        String[] classroom1 = {
                "班级管理","添加班级", "删除班级","查询成绩 ","修改班级"
        };
        String[] course1 = {
                "课程管理", "添加课程", "删除课程","查询课程 ","修改课程"
        };
        String[] account1 = {
                "账号管理",  "添加账号", "删除账号","修改密码"
        };

        JComboBox comboBox1 = new JComboBox(score1);
        JComboBox comboBox2 = new JComboBox(classroom1);
        JComboBox comboBox3 = new JComboBox(course1);
        JComboBox comboBox4 = new JComboBox(account1);
            JPanel comboBoxPanel = new JPanel();
        comboBoxPanel.add(comboBox1);
        comboBoxPanel.add(comboBox2);
        comboBoxPanel.add(comboBox3);
        comboBoxPanel.add(comboBox4);

    getContentPane().add(comboBoxPanel, BorderLayout.NORTH);


    pack();

}


 // 表格数据模型

    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowClosing(WindowEvent e) {
        // 处理窗口关闭事件
        // 可以在这里添加释放资源等相关逻辑

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {
        this.setVisible(false); // 当窗口被缩小时隐藏窗口
        // 创建MyTray对象
        myTray = new MyTray();
        myTray.SystemTrayInitial();
    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowActivated(WindowEvent e) {

    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }



    }

